﻿/*
   Author: Tomer Paz
   games.com
   2009
*/

/* Join/Start Dialog
	This dialog will ask player to consider [Join game or View] or [Start] game
*/



package monopoly.GameController.Dialogs {
	
	import monopoly.GameController.Dialogs.IDialog;
	import monopoly.GameController.Dialogs.Templates.*;
	import monopoly.Player.Player;
	import monopoly.Field.Field;
	import monopoly.Localization.*;
	import fl.controls.*;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.EventDispatcher;
	
	public class JoinViewStartDialogs extends Sprite implements IDialog
		{
		public static const ACTION_VIEW:uint	 = 0;
		public static const ACTION_JOIN:uint	 = 1;
		public static const ACTION_START:uint	 = 2;
		
		protected var chosen_option:uint = 0;
		protected var _dialog:BasicDialog;
		
		public function JoinViewStartDialogs(Title:String, Description:String, Option1:String, Option2:String)
			{
			_dialog = new BasicDialog(Title, Description, Option1, Option2);
			
			/* listen for dialog client respond */
			
			_dialog.addEventListener(MouseEvent.CLICK, onCmdDialogButtonClick);
			
			addChild(_dialog);
			}
			
		public override function set width(value:Number):void
			{
			_dialog.width = value;			
			}
		
		protected function onCmdDialogButtonClick(e:MouseEvent):void
			{
			var myStrings:ILocalLanguage = LocalLanguage.getInstance();
			
			if (e.target is Button)
				{
				if ( (e.target as Button).label == myStrings.DlgJVSView )
					{
					chosen_option = ACTION_VIEW;
					}
				else if ((e.target as Button).label == myStrings.DlgJVSJoin )
					{
					chosen_option = ACTION_JOIN;
					}
				else if ( (e.target as Button).label == myStrings.DlgJVSStart )
					{
					chosen_option = ACTION_START;
					}
				
				/* this command is done hence shutdown the BasicDialog */
			
				e.currentTarget.removeEventListener(MouseEvent.CLICK, onCmdDialogButtonClick);
				e.currentTarget.remove( );
				removeChild(DisplayObject(e.currentTarget));
				
				/* signal game controller we are done */
				
				dispatchEvent(new Event(Event.COMPLETE));
				}
			}
			
		public function get chosenAction():uint
					{
					return this.chosen_option;
					}
		}
}